package com.corpgovernment.travelstandard.controller;

import com.corpgovernment.api.travelstandard.bo.AirportTransferStandardRequestBO;
import com.corpgovernment.api.travelstandard.bo.AirportTransferStandardResponseBO;
import com.corpgovernment.api.travelstandard.bo.TrainTransferStandardRequestBO;
import com.corpgovernment.api.travelstandard.bo.TrainTransferStandardResponseBO;
import com.corpgovernment.api.travelstandard.enums.*;
import com.corpgovernment.api.travelstandard.vo.*;
import com.corpgovernment.api.travelstandard.vo.CommonTravelStandradShow.*;
import com.corpgovernment.api.travelstandard.vo.car.MbTravelstandCarModelVo;
import com.corpgovernment.api.travelstandard.vo.car.MbTravelstandCarVo;
import com.corpgovernment.api.travelstandard.vo.intlflight.MbTravelstandIntlFlightVo;
import com.corpgovernment.api.travelstandard.vo.response.TravelStandradShow1Response;
import com.corpgovernment.common.base.BaseUserInfo;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.common.currency.bo.CurrencyExchangeBO;
import com.corpgovernment.common.utils.DateUtil;
import com.corpgovernment.organization.constant.CommonConst;
import com.corpgovernment.travelstandard.impl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;


@RestController
@RequestMapping("commonManage")
public class CommonManageController {

	@Autowired
	private MbTravelstandTrainService travelstandTrainService;
	@Autowired
	private MbTravelstandFlightService travelstandFlightService;
	@Autowired
	private MbTravelstandTrainSeatService travelstandTrainSeatService;
	@Autowired
	private MbTravelstandHotelService mbTravelstandHotelService;
	@Autowired
	private MbTravelstandHotelPriceService mbTravelstandHotelPriceService;
	@Autowired
	private MbTravelstandHotelQuarterService mbTravelstandHotelQuarterService;
	@Autowired
	private MbTravelstandFlightTimeService mbTravelstandFlightTimeService;
	@Autowired
	private MbTravelstandIntlFlightService mbTravelstandIntlFlightService;
	@Autowired
	private MbTravelstandCarService mbTravelstandCarService;
	@Autowired
	private MbTravelstandCarModelService mbTravelstandCarModelService;
	@Autowired
	private AirportTransferStandardService airportTransferStandardService;
	@Autowired
	private TrainTransferStandardService trainTransferStandardService;
	@Autowired
	private MbTravelstandCurrencyExchangeService mbTravelstandCurrencyExchangeService;

	private final static String[] WEEK = {"每天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"};

	private final static String[] STAR_NAMES = {"不限", "一星级", "二星级", "三星级", "四星级", "五星级", "六星级"};

	/**
	 * APP-展示某个人下所有差标信息
	 */
	@RequestMapping("travelStandradShow")
	public JSONResult<CommonTravelStandradShow> travelStandardShow(BaseUserInfo baseUserInfo) {
		String orgId = baseUserInfo.getOrgId();
		String uid = baseUserInfo.getUid();
		return JSONResult.success(showInfo(orgId, uid));
	}

	/**
	 * PCBOOK-展示某个人下所有差标信息1
	 *
	 * @return
	 */
	@RequestMapping("travelStandradShow1")
	public JSONResult<TravelStandradShow1Response> travelStandardShow1(BaseUserInfo baseUserInfo) {
		String orgId = baseUserInfo.getOrgId();
		String uid = baseUserInfo.getUid();
		return JSONResult.success(showInfo1(orgId, uid));
	}

	/**
	 * SOA-展示某个人下所有差标信息
	 *
	 * @return
	 */
	@RequestMapping("travelStandardShowSoa")
	public JSONResult<CommonTravelStandradShow> travelStandardShowSoa(@RequestParam(value = "uid") String uid, @RequestParam(value = "orgId") String orgId) {
		return JSONResult.success(showInfo(orgId, uid));
	}

	/**
	 * SOA-展示某个人下所有差标信息1
	 *
	 * @return
	 */
	@RequestMapping("travelStandradShow1Soa")
	public JSONResult<TravelStandradShow1Response> travelStandardShow1Soa(@RequestParam(value = "uid") String uid, @RequestParam(value = "orgId") String orgId) {
		return JSONResult.success(showInfo1(orgId, uid));
	}

	/**
	 * 差标展示方式1
	 *
	 * @return
	 */
	private CommonTravelStandradShow showInfo(String orgId, String uid) {
		CommonTravelStandradShow commonTravelStandradShow = new CommonTravelStandradShow();
		commonTravelStandradShow.setCar(this.getCar(uid, orgId));
		commonTravelStandradShow.setFlight(this.getFlight(uid, orgId));
		commonTravelStandradShow.setIntlFlight(this.getIntlFlight(uid, orgId));
		commonTravelStandradShow.setTrain(this.getTrain(uid, orgId));
		commonTravelStandradShow.setHotel(this.getHotel(uid, orgId));
		commonTravelStandradShow.setIntlHotel(this.getIntlHotel(uid, orgId));
		commonTravelStandradShow.setAirportTransfer(this.getAirportTransfer(uid, orgId));
		commonTravelStandradShow.setTrainTransfer(this.getTrainTransfer(uid, orgId));
		return commonTravelStandradShow;
	}

	private CommonTravelStandradShow.IntlHotelTravelStandardVo getIntlHotel(String uid, String orgId) {
		CommonTravelStandradShow.IntlHotelTravelStandardVo travelStandardVo = new CommonTravelStandradShow.IntlHotelTravelStandardVo();
		//国际酒店
		MbTravelstandHotelVo travelstandard = mbTravelstandHotelService.getMbTravelstandHotelVoByuidAndOrgId(uid, orgId, null);
		if (travelstandard == null) {
			return travelStandardVo;
		}
		List<MbTravelstandHotelPriceVo> mbTravelstandHotelPriceVos = mbTravelstandHotelPriceService.list(new MbTravelstandHotelPriceVo() {{
			setTsHotelId(travelstandard.getId());
			setHotelType("1");
		}});
		//将其它地区放在最后面
		for (MbTravelstandHotelPriceVo mbTravelstandHotelPriceVo : mbTravelstandHotelPriceVos) {
			if (AreaTypeEnum.TYPE_1.getCode().equals(mbTravelstandHotelPriceVo.getAreaType())) {
				mbTravelstandHotelPriceVos.remove(mbTravelstandHotelPriceVo);
				mbTravelstandHotelPriceVos.add(mbTravelstandHotelPriceVo);
				break;
			}
		}
		if (HotelSwitchEnum.priceSwitch.E.getCode().equals(travelstandard.getPriceSwitchIntl())) {
			List<CommonTravelStandradShow.IntlHotelTravelStandardVo.Info> infos = new ArrayList<>();
			for (MbTravelstandHotelPriceVo mbTravelstandHotelPriceVo : mbTravelstandHotelPriceVos) {
				CommonTravelStandradShow.IntlHotelTravelStandardVo.Info info = new CommonTravelStandradShow.IntlHotelTravelStandardVo.Info();
				info.setAreaId(String.valueOf(mbTravelstandHotelPriceVo.getTsHotelAreaId()));
				info.setAreaName(mbTravelstandHotelPriceVo.getAreaName());
				info.setAreaType(mbTravelstandHotelPriceVo.getAreaType());
				//价格信息列表
				List<CommonTravelStandradShow.IntlHotelTravelStandardVo.Info.DetailVo> detailVos = new ArrayList<>();
				//默认的地区价格信息
				CommonTravelStandradShow.IntlHotelTravelStandardVo.Info.DetailVo defaultDetailVo = new CommonTravelStandradShow.IntlHotelTravelStandardVo.Info.DetailVo();
				if (mbTravelstandHotelPriceVo.getPriceUpperLimit() != null) {
					defaultDetailVo.setAreaPrice(mbTravelstandCurrencyExchangeService.showContext(mbTravelstandHotelPriceVo.getCurrencyCode(),mbTravelstandHotelPriceVo.getPriceUpperLimit()));
				}
				defaultDetailVo.setAreaStar(mbTravelstandHotelPriceVo.getStar() == null ? STAR_NAMES[0] : STAR_NAMES[mbTravelstandHotelPriceVo.getStar()]);
				detailVos.add(defaultDetailVo);
				//假如有淡旺季管控，添加淡旺季管控价格信息
				if (HotelSwitchEnum.QuarterSwitch.E.getCode().equals(travelstandard.getQuarterSwitch())) {
					List<MbTravelstandHotelQuarterVo> mbTravelstandHotelQuarterVos = mbTravelstandHotelQuarterService.list(new MbTravelstandHotelQuarterVo().setTsHotelId(travelstandard.getId()).setTsHotelAreaId(mbTravelstandHotelPriceVo.getTsHotelAreaId()));
					for (MbTravelstandHotelQuarterVo mbTravelstandHotelQuarterVo : mbTravelstandHotelQuarterVos) {
						//判断淡旺季管控是否过期
						long nowTime = System.currentTimeMillis();
						if (mbTravelstandHotelQuarterVo.getBeginDate() == null || mbTravelstandHotelQuarterVo.getEndDate() == null) {
							continue;
						}
						if (nowTime >= mbTravelstandHotelQuarterVo.getBeginDate().getTime() && nowTime <= mbTravelstandHotelQuarterVo.getEndDate().getTime()) {
							CommonTravelStandradShow.IntlHotelTravelStandardVo.Info.DetailVo detailVo = new CommonTravelStandradShow.IntlHotelTravelStandardVo.Info.DetailVo();
							detailVo.setDateRange(DateUtil.dateToString(mbTravelstandHotelQuarterVo.getBeginDate(), DateUtil.DF_YMD_DOT) + "-" + DateUtil.dateToString(mbTravelstandHotelQuarterVo.getEndDate(), DateUtil.DF_YMD_DOT));
							detailVo.setAreaStar(mbTravelstandHotelPriceVo.getStar() == null ? STAR_NAMES[0] : STAR_NAMES[mbTravelstandHotelPriceVo.getStar()]);
							if (mbTravelstandHotelQuarterVo.getPriceUpperLimit() != null) {
								detailVo.setAreaPrice("￥" + mbTravelstandHotelQuarterVo.getPriceUpperLimit().setScale(0, RoundingMode.HALF_DOWN).toString() + "及以下");
							}
							detailVos.add(detailVo);
						}
					}
				}

				//同住差标添加
				for (CommonTravelStandradShow.IntlHotelTravelStandardVo.Info.DetailVo detailVo : detailVos) {
					detailVo.setSharedManageStatus(Objects.equals(travelstandard.getSharedManageStatus(), CommonConst.TURN_ON) ? "是" : "否");
					detailVo.setHotelManageRules(
							Objects.equals(travelstandard.getSharedManageStatus(), CommonConst.TURN_ON) ? HotelManageRulesEnum.getDesc(travelstandard.getHotelManageRules()) : "");
				}
				info.setDetailList(detailVos);
				infos.add(info);
			}
			travelStandardVo.setInfos(infos);
		}
		return travelStandardVo;
	}

	/**
	 * 酒店差标
	 *
	 * @param uid
	 * @param orgId
	 * @return
	 */
	private HotelTravelStandardVo getHotel(String uid, String orgId) {
		CommonTravelStandradShow.HotelTravelStandardVo travelStandardVo = new CommonTravelStandradShow.HotelTravelStandardVo();
		//酒店
		MbTravelstandHotelVo travelstandard = mbTravelstandHotelService.getMbTravelstandHotelVoByuidAndOrgId(uid, orgId, null);
		if (travelstandard == null) {
			return travelStandardVo;
		}
		List<MbTravelstandHotelPriceVo> mbTravelstandHotelPriceVos = mbTravelstandHotelPriceService.list(new MbTravelstandHotelPriceVo() {{
			setTsHotelId(travelstandard.getId());
			setHotelType("0");
		}});
		//将其它地区放在最后面
		for (MbTravelstandHotelPriceVo mbTravelstandHotelPriceVo : mbTravelstandHotelPriceVos) {
			if (AreaTypeEnum.TYPE_1.getCode().equals(mbTravelstandHotelPriceVo.getAreaType())) {
				mbTravelstandHotelPriceVos.remove(mbTravelstandHotelPriceVo);
				mbTravelstandHotelPriceVos.add(mbTravelstandHotelPriceVo);
				break;
			}
		}
		if (HotelSwitchEnum.priceSwitch.E.getCode().equals(travelstandard.getPriceSwitch())) {
			List<CommonTravelStandradShow.HotelTravelStandardVo.Info> infos = new ArrayList<>();
			for (MbTravelstandHotelPriceVo mbTravelstandHotelPriceVo : mbTravelstandHotelPriceVos) {
				CommonTravelStandradShow.HotelTravelStandardVo.Info info = new CommonTravelStandradShow.HotelTravelStandardVo.Info();
				info.setAreaId(String.valueOf(mbTravelstandHotelPriceVo.getTsHotelAreaId()));
				info.setAreaName(mbTravelstandHotelPriceVo.getAreaName());
				info.setAreaType(mbTravelstandHotelPriceVo.getAreaType());
				//价格信息列表
				List<CommonTravelStandradShow.HotelTravelStandardVo.Info.DetailVo> detailVos = new ArrayList<>();
				//默认的地区价格信息
				CommonTravelStandradShow.HotelTravelStandardVo.Info.DetailVo defaultDetailVo = new CommonTravelStandradShow.HotelTravelStandardVo.Info.DetailVo();
				if (mbTravelstandHotelPriceVo.getPriceUpperLimit() != null) {
					defaultDetailVo.setAreaPrice("￥" + mbTravelstandHotelPriceVo.getPriceUpperLimit().setScale(0, RoundingMode.HALF_DOWN).toString() + "及以下");
				}
				defaultDetailVo.setAreaStar(mbTravelstandHotelPriceVo.getStar() == null ? STAR_NAMES[0] : STAR_NAMES[mbTravelstandHotelPriceVo.getStar()]);
				detailVos.add(defaultDetailVo);
				//假如有淡旺季管控，添加淡旺季管控价格信息
				if (HotelSwitchEnum.QuarterSwitch.E.getCode().equals(travelstandard.getQuarterSwitch())) {
					List<MbTravelstandHotelQuarterVo> mbTravelstandHotelQuarterVos = mbTravelstandHotelQuarterService.list(new MbTravelstandHotelQuarterVo().setTsHotelId(travelstandard.getId()).setTsHotelAreaId(mbTravelstandHotelPriceVo.getTsHotelAreaId()));
					for (MbTravelstandHotelQuarterVo mbTravelstandHotelQuarterVo : mbTravelstandHotelQuarterVos) {
						//判断淡旺季管控是否过期
						long nowTime = System.currentTimeMillis();
						if (mbTravelstandHotelQuarterVo.getBeginDate() == null || mbTravelstandHotelQuarterVo.getEndDate() == null) {
							continue;
						}
						if (nowTime >= mbTravelstandHotelQuarterVo.getBeginDate().getTime() && nowTime <= mbTravelstandHotelQuarterVo.getEndDate().getTime()) {
							CommonTravelStandradShow.HotelTravelStandardVo.Info.DetailVo detailVo = new CommonTravelStandradShow.HotelTravelStandardVo.Info.DetailVo();
							detailVo.setDateRange(DateUtil.dateToString(mbTravelstandHotelQuarterVo.getBeginDate(), DateUtil.DF_YMD_DOT) + "-" + DateUtil.dateToString(mbTravelstandHotelQuarterVo.getEndDate(), DateUtil.DF_YMD_DOT));
							detailVo.setAreaStar(mbTravelstandHotelPriceVo.getStar() == null ? STAR_NAMES[0] : STAR_NAMES[mbTravelstandHotelPriceVo.getStar()]);
							if (mbTravelstandHotelQuarterVo.getPriceUpperLimit() != null) {
								detailVo.setAreaPrice("￥" + mbTravelstandHotelQuarterVo.getPriceUpperLimit().setScale(0, RoundingMode.HALF_DOWN).toString() + "及以下");
							}
							detailVos.add(detailVo);
						}
					}
				}
				//同住差标添加
				for (HotelTravelStandardVo.Info.DetailVo detailVo : detailVos) {
					detailVo.setSharedManageStatus(Objects.equals(travelstandard.getSharedManageStatus(), CommonConst.TURN_ON) ? "是" : "否");
					detailVo.setHotelManageRules(
							Objects.equals(travelstandard.getSharedManageStatus(), CommonConst.TURN_ON) ? HotelManageRulesEnum.getDesc(travelstandard.getHotelManageRules()) : "");
				}
				info.setDetailList(detailVos);
				infos.add(info);
			}
			travelStandardVo.setInfos(infos);
		}
		return travelStandardVo;
	}

	/**
	 * 火车差标
	 *
	 * @param uid
	 * @param orgId
	 * @return
	 */
	private TrainTravelStandardVo getTrain(String uid, String orgId) {
		CommonTravelStandradShow.TrainTravelStandardVo travelStandardVo = new CommonTravelStandradShow.TrainTravelStandardVo();
		//火车票
		MbTravelstandTrainVo travelStandard = travelstandTrainService.getMbTravelstandTrainVoByuidAndOrgId(uid, orgId, null);
		if (travelStandard == null) {
			return travelStandardVo;
		}
		StringBuilder content = new StringBuilder();
		if (travelStandard.getSeatSwitch().equals(TrainSwitchEnum.seatSwitch.E.getCode())) {
			List<MbTravelstandTrainSeatVo> travelstandTrainSeatVos = travelstandTrainSeatService.list(new MbTravelstandTrainSeatVo() {{
				setTsTrainId(travelStandard.getId());
			}});
			for (MbTravelstandTrainSeatVo travelstandTrainSeatVo : travelstandTrainSeatVos) {
				content.append(travelstandTrainSeatVo.getSeatName());
				content.append(",");
			}
			if (travelstandTrainSeatVos.size() > 0) {
				content.deleteCharAt(content.length() - 1);
			}
			travelStandardVo.setSeatName(content.toString());
		}
		return travelStandardVo;
	}

	/**
	 * 机票差标
	 *
	 * @param uid
	 * @param orgId
	 * @return
	 */
	private FlightTravelStandardVo getFlight(String uid, String orgId) {
		CommonTravelStandradShow.FlightTravelStandardVo travelStandardVo = new CommonTravelStandradShow.FlightTravelStandardVo();
		//机票
		MbTravelstandFlightVo travelStandard = travelstandFlightService.getMbTravelstandFlightVoByuidAndOrgId(uid, orgId, null);
		if (travelStandard == null) {
			return travelStandardVo;
		}
		//舱等/折扣
		StringBuilder content = new StringBuilder();
		if (FlightSwitchEnum.ClassDiscountSwitch.C.getCode().equals(travelStandard.getClassDiscountSwitch())) {
			List<ClazzEnum> clazzEnums = ClazzEnum.getLowerClazzEnumThanCode(travelStandard.getClassClass());
			for (ClazzEnum clazzEnum : clazzEnums) {
				content.append(clazzEnum.getName()).append("、");
			}
			if (clazzEnums.size() > 0) {
				content.deleteCharAt(content.length() - 1);
			}
			travelStandardVo.setClazz(content.toString());
		}
		if (FlightSwitchEnum.ClassDiscountSwitch.D.getCode().equals(travelStandard.getClassDiscountSwitch())) {
			List<ClazzEnum> clazzEnums = ClazzEnum.getLowerClazzEnumThanCode(travelStandard.getDiscountClass());
			for (ClazzEnum clazzEnum : clazzEnums) {
				content.append(clazzEnum.getName());
				if (clazzEnum.getCode().equals(travelStandard.getDiscountClass())) {
					content.append(travelStandard.getDiscountNum().setScale(1, RoundingMode.HALF_UP).toString());
					content.append("折");
				}
				content.append(",");
			}
			if (clazzEnums.size() > 0) {
				content.deleteCharAt(content.length() - 1);
			}
			travelStandardVo.setDiscount(content.toString());
		}
		//低价
		if (FlightSwitchEnum.LowpriceSwitch.E.getCode().equals(travelStandard.getLowpriceSwitch())) {
			StringBuilder lowpriceContent = new StringBuilder();
			lowpriceContent.append("需订");
			lowpriceContent.append(travelStandard.getLowpriceCompareTimeStart() == null ? null : DateUtil.dateToString(travelStandard.getLowpriceCompareTimeStart(), DateUtil.DF_HM));
			lowpriceContent.append("-");
			lowpriceContent.append(travelStandard.getLowpriceCompareTimeEnd() == null ? null : DateUtil.dateToString(travelStandard.getLowpriceCompareTimeEnd(), DateUtil.DF_HM));
			lowpriceContent.append("时间段内出发时间前后");
			lowpriceContent.append(travelStandard.getLowpriceTimeOption());
			lowpriceContent.append("分钟内的最低价");
			travelStandardVo.setLowControl(lowpriceContent.toString());
		}
		//公里数
		if (FlightSwitchEnum.MileageSwitch.E.getCode().equals(travelStandard.getMileageSwitch())) {
			if (travelStandard.getMileageMinMileageNumber() != null) {
				travelStandardVo.setMileageControl(travelStandard.getMileageMinMileageNumber() + "公里以上可预订机票");
			}
		}
		//提前
		if (FlightSwitchEnum.AdvancedbookSwitch.E.getCode().equals(travelStandard.getAdvancedbookSwitch())) {
			if (travelStandard.getAdvancedbookAdvancedDayNum() != null) {
				travelStandardVo.setAdvancedBook("提前" + travelStandard.getAdvancedbookAdvancedDayNum() + "天预订");
			}
		}
		//金额
		if (FlightSwitchEnum.AmountControlSwitch.E.getCode().equals(travelStandard.getAmountControlSwitch())) {
			if (travelStandard.getAmountControlNum() != null) {
				travelStandardVo.setAmountControlVo(mbTravelstandCurrencyExchangeService.showFlightAmountContext(
						CommonConst.CNY_CODE, travelStandard.getAmountControlNum()));
			}
		}
		//时间
		if (FlightSwitchEnum.TimeSwitch.E.getCode().equals(travelStandard.getTimeSwitch())) {
			List<MbTravelstandFlightTimeVo> mbTravelstandFlightTimeVos = mbTravelstandFlightTimeService.list(new MbTravelstandFlightTimeVo().setTsFlightId(travelStandard.getId()));
			List<String> timeInfos = new ArrayList<>();
			for (MbTravelstandFlightTimeVo mbTravelstandFlightTimeVo : mbTravelstandFlightTimeVos) {
				StringBuilder timeInfo = new StringBuilder();
				timeInfo.append(WEEK[mbTravelstandFlightTimeVo.getWeek()]);
				timeInfo.append(DateUtil.dateToHM(mbTravelstandFlightTimeVo.getStartTime()));
				timeInfo.append("-");
				timeInfo.append(DateUtil.dateToHM(mbTravelstandFlightTimeVo.getEndTime()));
				timeInfo.append("不可预订机票");
				timeInfos.add(timeInfo.toString());
			}
			travelStandardVo.setTimeControl(timeInfos);
		}
		return travelStandardVo;
	}

	private CarTravelStandardVo getCar(String uid, String orgId) {
		CommonTravelStandradShow.CarTravelStandardVo carTravelStandardVo = new CommonTravelStandradShow.CarTravelStandardVo();
		//用车
		MbTravelstandCarVo mbTravelstandCarVo = mbTravelstandCarService.getMbTravelstandCarVoByUidAndOrgId(uid, orgId, null);
		if (mbTravelstandCarVo == null) {
			return carTravelStandardVo;
		}
		if (CarSwitchEnum.PriceSwitch.E.getCode().equals(mbTravelstandCarVo.getPriceSwitch())) {
			if (mbTravelstandCarVo.getPriceUpperLimit() != null) {
				carTravelStandardVo.setCarPrice("￥" + mbTravelstandCarVo.getPriceUpperLimit() + "及以下");
			}
		}
		if (CarSwitchEnum.ModelSwitch.E.getCode().equals(mbTravelstandCarVo.getModelSwitch())) {
			List<MbTravelstandCarModelVo> mbTravelstandCarModelVos = mbTravelstandCarModelService.list(new MbTravelstandCarModelVo().setTsCarId(mbTravelstandCarVo.getId()));
			String modelName = mbTravelstandCarModelVos.stream().map(MbTravelstandCarModelVo::getModelName).distinct().collect(Collectors.joining("、"));
			carTravelStandardVo.setCarType(modelName);
//				carTravelStandardVo.setCarType(StringUtils.appendString(mbTravelstandCarModelVos, MbTravelstandCarModelVo.class, "modelName", "、", null, null));
		}
		return carTravelStandardVo;
	}

	private CommonTravelStandradShow.AirportTransferTravelStandardVo getAirportTransfer(String uid, String orgId){
		CommonTravelStandradShow.AirportTransferTravelStandardVo result = new CommonTravelStandradShow.AirportTransferTravelStandardVo();
		AirportTransferStandardResponseBO travelStandard = airportTransferStandardService.getTravelStandard(new AirportTransferStandardRequestBO(uid, orgId));
		travelStandard.getAirportTransferDescList().forEach(item ->{
			if (item.getTitle().indexOf("价格") > -1){
				result.setCarPrice(item.getContent());
			}
			if (item.getTitle().indexOf("车型") > -1){
				result.setCarType(item.getContent());
			}

		});
		return result;
	}

	private CommonTravelStandradShow.TrainTransferTravelStandardVo getTrainTransfer(String uid, String orgId){
		CommonTravelStandradShow.TrainTransferTravelStandardVo result = new CommonTravelStandradShow.TrainTransferTravelStandardVo();
		TrainTransferStandardResponseBO travelStandard = trainTransferStandardService.getTravelStandard(new TrainTransferStandardRequestBO(uid, orgId));
		travelStandard.getAirportTransferDescList().forEach(item ->{
			if (item.getTitle().indexOf("价格") > -1){
				result.setCarPrice(item.getContent());
			}
			if (item.getTitle().indexOf("车型") > -1){
				result.setCarType(item.getContent());
			}
		});
		return result;
	}

	/**
	 * 国际机票差标
	 *
	 * @param uid
	 * @param orgId
	 * @return
	 */
	private IntlFlightTravelStandardVo getIntlFlight(String uid, String orgId) {
		CommonTravelStandradShow.IntlFlightTravelStandardVo travelStandardVo = new CommonTravelStandradShow.IntlFlightTravelStandardVo();
		//国际机票
		MbTravelstandIntlFlightVo travelStandard = mbTravelstandIntlFlightService.getMbTravelstandIntlFlightVoByuidAndOrgId(uid, orgId, null);
		if (travelStandard == null) {
			return travelStandardVo;
		}
		//舱等
		StringBuilder content = new StringBuilder();
		if (Objects.equals(IntlFlightSwitchEnum.ClassSwitch.E.getCode(), travelStandard.getClassSwitch())) {
			List<ClazzEnum> clazzEnums = ClazzEnum.getLowerClazzEnumThanCode(travelStandard.getClassClass());
			for (ClazzEnum clazzEnum : clazzEnums) {
				content.append(clazzEnum.getName()).append("、");
			}
			if (clazzEnums.size() > 0) {
				content.deleteCharAt(content.length() - 1);
			}
			travelStandardVo.setClazz(content.toString());
		}
		//低价
		if (Objects.equals(FlightSwitchEnum.LowpriceSwitch.E.getCode(), travelStandard.getLowpriceSwitch())) {
			StringBuilder lowPriceContent = new StringBuilder();
			lowPriceContent.append("需订");
			lowPriceContent.append(Optional.ofNullable(travelStandard.getLowpriceCompareTimeStart()).map(e -> DateUtil.dateToString(e, DateUtil.DF_HM)).orElse(null));
			lowPriceContent.append("-");
			lowPriceContent.append(Optional.ofNullable(travelStandard.getLowpriceCompareTimeEnd()).map(e -> DateUtil.dateToString(e, DateUtil.DF_HM)).orElse(null));
			lowPriceContent.append("时间段内出发时间前后");
			lowPriceContent.append(travelStandard.getLowpriceTimeOption());
			lowPriceContent.append("分钟内的最低价");
			travelStandardVo.setLowControl(lowPriceContent.toString());
		}
		//提前
		if (FlightSwitchEnum.AdvancedbookSwitch.E.getCode().equals(travelStandard.getAdvancedbookSwitch())) {
			if (travelStandard.getAdvancedbookAdvancedDayNum() != null) {
				travelStandardVo.setAdvancedBook("提前" + travelStandard.getAdvancedbookAdvancedDayNum() + "天预订");
			}
		}
		//金额
		if (FlightSwitchEnum.AmountControlSwitch.E.getCode().equals(travelStandard.getAmountControlSwitch())) {
			if (travelStandard.getAmountControlNum() != null) {
				travelStandardVo.setAmountControlVo(mbTravelstandCurrencyExchangeService.showFlightAmountContext(
						travelStandard.getAmountControlCurrency(), travelStandard.getAmountControlNum()));
			}
		}
		return travelStandardVo;
	}

	/**
	 * 差标展示方式1
	 *
	 * @return { "status": 200, "msg": "SUCCESS", "data": { "travelStandard": [ { "title": "机票可订舱位（含折扣）：", "content": "经济舱4.5折" }, { "title": "火车票可选坐席：", "content": "一等座,二等双软,无座,硬卧" } ], "hotelTravelStandard": { "title": "酒店预订差旅规则", "area": [ { "id": "001", "name": "一线城市",
	 * "content": "不限" } ] }, "success": true } }
	 */
	private TravelStandradShow1Response showInfo1(String orgId, String uid) {
		TravelStandradShow1Response travelStandradShow1Response = new TravelStandradShow1Response();
		List<TravelStandradShow1Response.TravelStandardInfo> travelStandardInfos = new ArrayList<>();
		//机票
		TravelStandradShow1Response.TravelStandardInfo classDiscountInfo = new TravelStandradShow1Response.TravelStandardInfo();
		TravelStandradShow1Response.TravelStandardInfo lowpriceInfo = new TravelStandradShow1Response.TravelStandardInfo();
		MbTravelstandFlightVo travelstandFlightVo = travelstandFlightService.getMbTravelstandFlightVoByuidAndOrgId(uid, orgId, null);
		if (travelstandFlightVo != null) {
			//折扣/舱等信息填充
			StringBuilder classDiscountContent = new StringBuilder();
			if (FlightSwitchEnum.ClassDiscountSwitch.C.getCode().equals(travelstandFlightVo.getClassDiscountSwitch())) {
				classDiscountInfo.setTitle("机票可订舱位：");
				List<ClazzEnum> clazzEnums = ClazzEnum.getLowerClazzEnumThanCode(travelstandFlightVo.getClassClass());
				for (ClazzEnum clazzEnum : clazzEnums) {
					classDiscountContent.append(clazzEnum.getName()).append("、");
				}
				if (clazzEnums.size() > 0) {
					classDiscountContent.deleteCharAt(classDiscountContent.length() - 1);
				}
			}
			if (FlightSwitchEnum.ClassDiscountSwitch.D.getCode().equals(travelstandFlightVo.getClassDiscountSwitch())) {
				classDiscountInfo.setTitle("机票可订折扣：");
				ClazzEnum clazzEnum = ClazzEnum.getEnumByCode(travelstandFlightVo.getDiscountClass());
				classDiscountContent.append(clazzEnum == null ? null : clazzEnum.getName());
				classDiscountContent.append(travelstandFlightVo.getDiscountNum() == null ? null : travelstandFlightVo.getDiscountNum().setScale(1, RoundingMode.HALF_UP));
				classDiscountContent.append("折及以下");
			}
			if (FlightSwitchEnum.ClassDiscountSwitch.N.getCode().equals(travelstandFlightVo.getClassDiscountSwitch())) {
				classDiscountInfo.setTitle("机票可订舱位：");
				classDiscountContent.append("不限");
			}
			classDiscountInfo.setContent(classDiscountContent.toString());
			//低价信息填充
			StringBuilder lowpriceContent = new StringBuilder();
			if (FlightSwitchEnum.LowpriceSwitch.E.getCode().equals(travelstandFlightVo.getLowpriceSwitch())) {
				lowpriceContent.append("需订");
				lowpriceContent.append(travelstandFlightVo.getLowpriceCompareTimeStart() == null ? null : DateUtil.dateToString(travelstandFlightVo.getLowpriceCompareTimeStart(), DateUtil.DF_HM));
				lowpriceContent.append("-");
				lowpriceContent.append(travelstandFlightVo.getLowpriceCompareTimeEnd() == null ? null : DateUtil.dateToString(travelstandFlightVo.getLowpriceCompareTimeEnd(), DateUtil.DF_HM));
				lowpriceContent.append("时间段内出发时间前后");
				lowpriceContent.append(travelstandFlightVo.getLowpriceTimeOption());
				lowpriceContent.append("分钟内的最低价");
			} else if (FlightSwitchEnum.LowpriceSwitch.N.getCode().equals(travelstandFlightVo.getLowpriceSwitch())) {
				lowpriceContent.append("不限");
			}
			lowpriceInfo.setTitle("机票可订低价：");
			lowpriceInfo.setContent(lowpriceContent.toString());
		} else {
			classDiscountInfo.setTitle("机票可订舱位（含折扣）：");
			classDiscountInfo.setContent("不限");
			lowpriceInfo.setTitle("机票可订低价：");
			lowpriceInfo.setContent("不限");
		}
		travelStandardInfos.add(classDiscountInfo);
		travelStandardInfos.add(lowpriceInfo);
		//火车票
		MbTravelstandTrainVo travelstandTrainVo = travelstandTrainService.getMbTravelstandTrainVoByuidAndOrgId(uid, orgId, null);
		TravelStandradShow1Response.TravelStandardInfo travelStandardInfo2 = new TravelStandradShow1Response.TravelStandardInfo();
		if (travelstandTrainVo != null) {
			StringBuilder content = new StringBuilder();
			if (travelstandTrainVo.getSeatSwitch().equals(TrainSwitchEnum.seatSwitch.E.getCode())) {
				List<MbTravelstandTrainSeatVo> travelstandTrainSeatVos = travelstandTrainSeatService.list(new MbTravelstandTrainSeatVo() {{
					setTsTrainId(travelstandTrainVo.getId());
				}});
				for (MbTravelstandTrainSeatVo travelstandTrainSeatVo : travelstandTrainSeatVos) {
					content.append(travelstandTrainSeatVo.getSeatName());
					content.append(",");
				}
				if (travelstandTrainSeatVos.size() > 0) {
					content.deleteCharAt(content.length() - 1);
				}
			}
			if (travelstandTrainVo.getSeatSwitch().equals(TrainSwitchEnum.seatSwitch.N.getCode())) {
				content.append("不限");
			}
			travelStandardInfo2.setTitle("火车票可选坐席：");
			travelStandardInfo2.setContent(content.toString());
		} else {
			travelStandardInfo2.setTitle("火车票可选坐席：");
			travelStandardInfo2.setContent("不限");
		}
		travelStandardInfos.add(travelStandardInfo2);
		travelStandradShow1Response.setTravelStandard(travelStandardInfos);
		//酒店
		travelStandradShow1Response.setHotelTravelStandard(getHotelTravelStandard(orgId, uid));
		return travelStandradShow1Response;
	}

	private TravelStandradShow1Response.HotelTravelStandard getHotelTravelStandard(String orgId, String uid) {
		MbTravelstandHotelVo mbTravelstandHotelVo = mbTravelstandHotelService.getMbTravelstandHotelVoByuidAndOrgId(uid, orgId, null);
		TravelStandradShow1Response.HotelTravelStandard hotelTravelStandard = new TravelStandradShow1Response.HotelTravelStandard();
		if (mbTravelstandHotelVo != null) {
			hotelTravelStandard.setTitle("酒店预订差旅规则：");
			if (HotelSwitchEnum.priceSwitch.E.getCode().equals(mbTravelstandHotelVo.getPriceSwitch())) {
				List<TravelStandradShow1Response.HotelTravelStandard.AreaInfo> areaInfos = new ArrayList<>();
				List<MbTravelstandHotelPriceVo> mbTravelstandHotelPriceVos = mbTravelstandHotelPriceService.list(
						new MbTravelstandHotelPriceVo().setTsHotelId(mbTravelstandHotelVo.getId())
				);
				//将其它地区放在最后面
				for (MbTravelstandHotelPriceVo mbTravelstandHotelPriceVo : mbTravelstandHotelPriceVos) {
					if (AreaTypeEnum.TYPE_1.getCode().equals(mbTravelstandHotelPriceVo.getAreaType())) {
						mbTravelstandHotelPriceVos.remove(mbTravelstandHotelPriceVo);
						mbTravelstandHotelPriceVos.add(mbTravelstandHotelPriceVo);
						break;
					}
				}
				for (MbTravelstandHotelPriceVo mbTravelstandHotelPriceVo : mbTravelstandHotelPriceVos) {
					TravelStandradShow1Response.HotelTravelStandard.AreaInfo areaInfo = new TravelStandradShow1Response.HotelTravelStandard.AreaInfo();
					areaInfo.setName(mbTravelstandHotelPriceVo.getAreaName());
					areaInfo.setId(String.valueOf(mbTravelstandHotelPriceVo.getTsHotelAreaId()));
					StringBuilder content = new StringBuilder();
					if (mbTravelstandHotelPriceVo.getPriceUpperLimit() != null) {
						content.append("￥");
						content.append(mbTravelstandHotelPriceVo.getPriceUpperLimit().setScale(2, RoundingMode.HALF_UP).toString());
						content.append("及以下");
					} else {
						content.append("不限");
					}
					areaInfo.setContent(content.toString());
					areaInfos.add(areaInfo);
				}
				hotelTravelStandard.setArea(areaInfos);
			} else if (HotelSwitchEnum.priceSwitch.N.getCode().equals(mbTravelstandHotelVo.getPriceSwitch())) {
				hotelTravelStandard.setArea(null);
			}
		} else {
			hotelTravelStandard.setTitle("酒店预订差旅规则：");
			hotelTravelStandard.setArea(null);
		}
		return hotelTravelStandard;
	}


}
